﻿using System;
using System.CodeDom.Compiler;
using System.Linq;

namespace FBGraph.ClientGenerator.CodeGen
{
    public class CustomAttribute : CodeGenObject
    {
        public CustomAttribute(String name, params Argument[] parameters)
        {
            this.Name = name;
            this.NamedParameters = new ArgumentList(parameters);
        }

        public CustomAttribute(Type type, params Argument[] parameters) : this(type.Name, parameters) { }

        public String Name { get; set; }
        public ArgumentList NamedParameters { get; private set; }

        public override void Write(CodeGenWriter writer)
        {
            writer.Write('[');
            writer.Write(this.Name);
            if (this.NamedParameters.Any())
            {
                writer.Write('(');
                writer.Write(this.NamedParameters);
                writer.Write(')');
            }
            writer.Write(']');            
        }
    }
}
